<template>
  <div class="app-container">
    <wise-crud ref="wise-crud" :urls="urls" :fields="fields" :handle="handle">
      <template slot="outHandle">
        <el-button type="primary" class="activeBtn" icon="el-icon-plus" @click.native.prevent="addHandle">添加</el-button>
      </template>
      <template v-slot:handle="slotProps">

        <el-button v-if="slotProps.row.confirmStatus!==1" type="warning" size="small" class="activeBtn" round
          @click.native.prevent="editHandle(slotProps.row)">编辑</el-button>
        <el-button type="info" size="small" class="activeBtn" round @click.native.prevent="viewHandle(slotProps.row)">查看
        </el-button>
        <el-button v-if="slotProps.row.confirmStatus!==1" type="danger" size="small" class="activeBtn" round
          @click.native.prevent="removeHandle(slotProps.row)">删除</el-button>
      </template>
    </wise-crud>

    <add-inspection-sheet ref="addInspectionSheet" />
    <view-table ref="viewTable" />
  </div>
</template>

<script>
  import WiseCrud from '../../../../components/Crud/wiseCrud'
  import AddInspectionSheet from './AddInspectionSheet'
  import viewTable from './viewTable'
  import {
    postHandle
  } from '../../../../api'

  export default {
    name: 'InspectionSheet',
    components: {
      WiseCrud,
      AddInspectionSheet,
      viewTable
    },
    data() {
      return {
        handle: [],
        urls: {
          list: '/api/v1/welder-sbtx-second/inspection-comb/list',
          delete: `/api/v1/welder-sbtx-second/inspection-comb/remove/`
        },
        fields: [{
            label: '企业名称',
            prop: 'enterpriseInfo.name',
            type: 'text',
            use: ['table'],
          },

          {
            label: '编号',
            prop: 'serialNumber',
            type: 'text',
            use: ['table'],
          }, {
            label: '所属项目',
            prop: 'projectInfo.name',
            type: 'text',
            use: ['table']
          },
          {
            label: '动火作业单位',
            prop: 'hotWorkUnit',
            type: 'text',
            use: ['table']
          },
          {
            label: '动火级别',
            prop: 'hotLevel',
            type: 'text',
            use: ['table']
          },
          {
            label: '生产运行部门',
            prop: 'productionDepartment',
            type: 'text',
            use: ['table']
          },
          {
            label: '动火时间',
            prop: 'hotTime',
            type: 'datetime',
            format: 'YYYY-MM-DD HH:mm:ss',
            use: ['table']
          },
          {
            label: '动火监督部门',
            prop: 'supervisionDepartment',
            type: 'text',
            use: ['table']
          },
          {
            label: '天气情况',
            prop: 'weather',
            type: 'text',
            use: ['table']
          },
          {
            label: '操作',
            type: 'handle',
            use: ['table'],
            handle: [],
            tableWidth: 200
          }
        ],
        obj: {}
      }
    },
    computed: {


    },
    mounted() {
      this.$refs['addInspectionSheet'].$on('refreshTable', () => {
        this.$refs['wise-crud'].handleSearch(0)
      })
    },
    methods: {
      editHandle(row) {
        this.$refs['addInspectionSheet'].getObjectId(row)
        this.$refs['addInspectionSheet'].title = '编辑'
        this.$refs['addInspectionSheet'].dialog = true
      },
      viewHandle(row) {
        this.$refs['viewTable'].getObjectId(row)
        this.$refs['viewTable'].viewDialog = true
      },
      addHandle() {
        this.$refs['addInspectionSheet'].title = '添加'
        this.$refs['addInspectionSheet'].dialog = true
      },
      removeHandle({
        id
      }) {
        this.$confirm('此操作将删除该数据, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          postHandle(this.urls.delete + id).then(res => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.$refs['wise-crud'].handleSearch(0)
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      }
    }
  }
</script>

<style></style>